<?php
if ($_GET['id'] && $_GET['billno']) {
    $rowid = $_GET['id'];
    $billno=$_GET['billno'];
   

//including header.php 
    include '../../include/header.php';
//including page.php (It is a class which contain functions)
    include '../../libraries/page.php';
//created object for page.php
    $page = new page();
    session_start();
    $userid = $_SESSION['userid'];

    date_default_timezone_set('Asia/Calcutta');
    $date1 = date("Y-m-d H:i:s");

//checking the session
    if (!$_SESSION['username']) {
        header("location:../user/login.php");
    }

    if ($_GET['q'] == 'logout') {
        $page->user_logout();
        header("location:../user/login.php");
    }

  
    $sales_billing = 'active';
    include '../../include/navbar.php';
    ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script>                          
                function myCall() {
                    var request = $.ajax({
                        url: "bill_detail_update.php",
                        type: "POST",            
                        dataType: "html"
                    });
 
                    request.done(function(msg) {
                        $("#save_reply").html(msg);          
                    });
 
                    request.fail(function(jqXHR, textStatus) {
                        alert( "Request failed: " + textStatus );
                    });
                }
             
        </script>
    <div class="bread_crumb" style="margin-left: 2%">
        &laquo;  <a href="groups">Back</a>
    </div>
    <!----------------------------------Display the result message of Addition--------------------->
    <div  align="center"><? echo $msg; ?></div>
    <div  align="center" id="save_reply"></div>
    <!----------------------------------------------div for placing form here------------------------->
    <div  style="margin-left: auto;margin-right: auto; width:290px;margin-top:10%;">
        <h3 style="color:#777;margin-left: 25%;">Edit Bill Detail</h3>
        <br />
        <?
        //php code to get the data from groups table 
        $detail = mysql_query("select * from billdetails where rowid='$rowid'");
        $id = 0;
        while ($detail_data = mysql_fetch_array($detail)) {

        $productid = $detail_data['productid'];
        $qty = $detail_data['qty'];
         $discount = $detail_data['discount'];
         $individual_discount=$discount/$qty;
        $products = mysql_query("select name from products where productid='$productid'");
        $products_data = mysql_fetch_array($products);
        $productname=$products_data['name'];

        ?>

        <?
        }
        ?>
        <!---------------------------------form------------------------------------------------>
        <form method="POST"  action="bill_detail_update.php">
            <label>Product name</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="name" value="<?= $productname; ?>"  readonly="readonly">
            <input class="input-xlarge" id="focusedInput" type="hidden" name="rowid" value="<?= $rowid; ?>" >
            <input class="input-xlarge" id="focusedInput" type="hidden" name="billno" value="<?= $billno; ?>" >
            
            <label>Qty</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="qty" value="<?= $qty; ?>"  required>
            
                <label>Discount</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="discount" value="<?= $individual_discount; ?>"  >


            <button class="btn btn-inverse" type="submit"  name="submit" style="float:right; margin-right: 15px; margin-top: 20px;">Add Group</button 
        </form>
    </div>

    <?php
//including footer.php
    include '../../include/footer.php';
    ?>
    <?php
}
?>